Skip to content

perf: try to cache inner contexts of overloads #19408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Jul 8, 2025

Improves #14978 and marginally improves nested overloads checking in general. This is not ready for review, but I would appreciate any in-progress feedback on the idea itself.

If I understand correctly, this change should not change any behavior at all: infer_arg_types_in_empty_context is almost pure.

This change halves colour check time.

Another very similar problem arises when checking overloaded binary operations (like in #14978), they do not translate directly into a series of overloads check but repeat the whole process for every node instead. Improving overload checking helps with that, but the result is still slow beyond reasonable. I'll try to push this further later in a separate PR.

This comment has been minimized.

@sterliakov sterliakov changed the title WIP: try to cache inner contexts of overloads and ops WIP: try to cache inner contexts of overloads Jul 8, 2025

This comment has been minimized.

@sterliakov sterliakov closed this Jul 8, 2025
@sterliakov sterliakov reopened this Jul 9, 2025
@sterliakov sterliakov force-pushed the experiments/st-overload-cache branch from c7da595 to a1f8c77 Compare July 9, 2025 15:00

This comment has been minimized.

@sterliakov
Copy link
Collaborator Author

Now this is what I wanted to see: no behavior changes and colour brought down to 27 minutes from 50 - almost halved!

This is not ready for code review, removing draft status to get some feedback on the idea itself. I do not particularly like using id(expr) as a cache key, but it should be OK? TempNode is excluded, and everything else should not be subject to ID rot because objects actually remain in the parsed tree for the whole lifetime of checker, their IDs cannot get reused, and we should not construct any nodes other than TempNode while checking function calls.

@sterliakov sterliakov marked this pull request as ready for review July 9, 2025 17:18
Copy link
Contributor

github-actions bot commented Jul 9, 2025

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sterliakov sterliakov changed the title WIP: try to cache inner contexts of overloads perf: try to cache inner contexts of overloads Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant